<style>
	main { width: 100%; height: 500px; display: flex; flex-flow: column nowrap; justify-content: center; align-items: center; }
	main input { width: 300px; height: 32px; margin-top: 20px; }
	main button { width: 120px; height: 32px; margin-top: 20px; }
</style>

<input type="password" name="oldpassword" placeholder="请输入旧密码">
<input type="password" name="password" placeholder="请输入新密码">
<input type="password" name="password2" placeholder="请再次输入新密码">
<button class="btn_change">变更</button>

<script>
	$().ready(function(){
		$("button.btn_change").click(function(){
			var old = $("input[name=oldpassword]").val();
			var pw = $("input[name=password]").val();
			var pw2 = $("input[name=password2]").val();
			if(!old || !pw  || !pw2 ){
				alert("请输入旧密码和将要使用的新密码");
			}else if(pw != pw2){
				alert("两次输入新密码不一致");
			}else{
				var conditions = JSON.stringify({user_id: userlogin.userID});
				$.get(dataDomain + "curd.php", {do: 'select', table: 'tj.operation_users', conditions: conditions} , function(r){
					// console.log(r)
					if(r[0].password != hex_md5(old)){
						alert('旧密码不正确')
					}else{
						var fields = JSON.stringify({password: hex_md5(pw)});
						var conditions = JSON.stringify({user_id: userlogin.userID});
						$.get(dataDomain + "curd.php", {do: 'update', table: "tj.operation_users", fields: fields, conditions: conditions}, function(r){
							console.log(r)
							sessionStorage.removeItem("userlogin");
							window.location.reload();
						})
					}
				}, 'json')
			}
		})

		$("main input[type=password]").keyup(function(e){
			if(e.keyCode == 13){
				$("button.btn_change").click();
			}
		})
	})
</script>